package vip.bblog.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import vip.bblog.common.utils.BaseResult;
import vip.bblog.user.dao.BlogQqUserMapper;
import vip.bblog.user.entity.BlogQqUser;
import vip.bblog.user.service.BlogQqUserService;

/**
 * <p>
 * QQ用户基本信息表 服务实现类
 * </p>
 *
 * @author yuyong
 * @since 2019-04-28
 */
@Service
public class BlogQqUserServiceImpl extends ServiceImpl<BlogQqUserMapper, BlogQqUser> implements BlogQqUserService {

    @Autowired
    private BlogQqUserMapper qqUserMapper;

    /**
     * 根据openId禁用用户
     *
     * @param openId
     * @return
     */
    @Override
    public BaseResult<Object> disableByOpenId(String openId) {
        BlogQqUser qqUser = new BlogQqUser();
        qqUser.setOpenid(openId);
        qqUser.setStatus(0);
        qqUserMapper.updateById(qqUser);
        return new BaseResult<>();
    }

    /**
     * 模糊分页查询用户
     *
     * @param page
     * @param qqUser
     * @return
     */
    @Override
    public BaseResult<Object> selectPageByExample(Page<BlogQqUser> page, BlogQqUser qqUser) {
        QueryWrapper<BlogQqUser> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(qqUser.getNickname())) {
            queryWrapper.like("nickname", qqUser.getNickname());
        }
        if (StringUtils.isNotBlank(qqUser.getArea())) {
            queryWrapper.like("area", qqUser.getArea());
        }
        if (StringUtils.isNotBlank(qqUser.getGender())) {
            queryWrapper.eq("gender", qqUser.getGender());
        }
        if (null == qqUser.getStatus()) {
            queryWrapper.eq("status", 1);
        } else {
            queryWrapper.eq("status", qqUser.getStatus());
        }
        IPage<BlogQqUser> pageInfo = qqUserMapper.selectPage(page, queryWrapper);
        return new BaseResult<>(pageInfo);
    }
}
